* Opening the data
import delimited "/Users/samueljohnston/Documents/R Code/Thesis/Internal Homogenisation Dataset.csv", varnames(1)

*To transform the dependent variable into a percentage:
gen ihposition = ih_position*100 

*To figure out what variables are strings, and transform them into numeric variables:
describe

gen election_year_n = real(election_year)
gen centre_left_decent_sal_n = real(centre_left_decent_sal)
gen gdp_per_capita_n = real(gdp_per_capita)

*To run the regression with year FEs, and plot the graph:
regress ihposition i.eu_member_lagged##c.rai eu_change lagged_ih lagged_rr_presence lagged_er_presence established_party_distance ///
centre_left_decent_sal_n centre_right_decent_sal international_migrant_stock elf economic_growth gdp_per_capita_n unemployment ///
disproportionality parfam eastern_european i.election_year_n, robust

eststo one_SD_below: margins, dydx(eu_member_lagged) at (rai=(4.71)) post

regress ihposition i.eu_member_lagged##c.rai eu_change lagged_ih lagged_rr_presence lagged_er_presence established_party_distance ///
centre_left_decent_sal_n centre_right_decent_sal international_migrant_stock elf economic_growth gdp_per_capita_n unemployment ///
disproportionality parfam eastern_european i.election_year_n, robust

eststo mean: margins, dydx(eu_member_lagged) at (rai=(17.17)) post

regress ihposition i.eu_member_lagged##c.rai eu_change lagged_ih lagged_rr_presence lagged_er_presence established_party_distance ///
centre_left_decent_sal_n centre_right_decent_sal international_migrant_stock elf economic_growth gdp_per_capita_n unemployment ///
disproportionality parfam eastern_european i.election_year_n, robust

eststo one_SD_above: margins, dydx(eu_member_lagged) at (rai=(29.63)) post


coefplot (one_SD_below, msymbol(O) mcolor(black) ciopts(recast(. rcap) color(. black))) ///
(mean, msymbol(S) mcolor(black) ciopts(recast(. rcap) color(. black))) ///
(one_SD_above, msymbol(D) mcolor(black) ciopts(recast(. rcap) color(. black))), ///
vert  yline(0) ///
graphregion(color(white))
